// @ts-ignore
/* eslint-disable */
import { ResponseData } from '@/utils/request';
import { request } from 'umi';

/** 获取当前的用户 GET /api/currentUser */
export async function currentUser(options?: { [key: string]: any }): Promise<API.CurrentUser> {
  const res = await request<ResponseData<API.CurrentUser>>('/login/currentUser', {
    method: 'GET',
    ...(options || {}),
  });

  return {
    ...res.data,
  };
}

/** 退出登录接口 POST /api/login/outLogin */
export async function outLogin(options?: { [key: string]: any }) {
  return request<Record<string, any>>('/login/outLogin', {
    method: 'POST',
    ...(options || {}),
  });
}

/** 登录接口 POST /api/login/account */
export async function login(body: API.LoginParams, options?: { [key: string]: any }) {
  console.log('body', body);

  const res = await request<ResponseData<API.LoginResult>>('/login/account', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });

  const loginResult: API.LoginResult = {
    status: res.code === 0 ? 'ok' : 'error',
    accesses: res.data.accesses,
  };

  return loginResult;
}

/** 此处后端没有提供注释 GET /api/notices */
export async function getNotices(options?: { [key: string]: any }) {
  return request<API.NoticeIconList>('/notification/message/list', {
    method: 'GET',
    ...(options || {}),
  });
}
